package cn.bocweb.spinning.view.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;

import butterknife.Bind;
import butterknife.ButterKnife;
import cn.bocweb.spinning.R;
import cn.bocweb.spinning.view.adapter.InfoItemAdapter;
import cn.bocweb.spinning.view.adapter.ProfessorAnswerAdapter;
import cn.bocweb.spinning.view.common.BaseActivity;

public class ProfessorAnswerActivity extends BaseActivity {

    @Bind(R.id.toolbar)
    Toolbar toolbar;
    @Bind(R.id.professor_answer_tips)
    RecyclerView professorAnswerTips;
    @Bind(R.id.professor_answer_list)
    RecyclerView professorAnswerList;

    InfoItemAdapter infoItemAdapter;
    ProfessorAnswerAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_professor_answer);
        ButterKnife.bind(this);
        initToolbar();
        initTips();
        initList();
    }

    private void initList() {
        adapter = new ProfessorAnswerAdapter();
        LinearLayoutManager manager = new LinearLayoutManager(this);
        manager.setOrientation(LinearLayoutManager.VERTICAL);
        professorAnswerList.setAdapter(infoItemAdapter);
        professorAnswerList.setLayoutManager(manager);
        professorAnswerList.setAdapter(adapter);
    }

    private void initTips() {
        infoItemAdapter = new InfoItemAdapter(null);
        LinearLayoutManager manager = new LinearLayoutManager(this);
        manager.setOrientation(LinearLayoutManager.HORIZONTAL);
        professorAnswerTips.setAdapter(infoItemAdapter);
        professorAnswerTips.setLayoutManager(manager);
        infoItemAdapter.setOnItemClickListener(new InfoItemAdapter.OnItemClickListener() {
            @Override
            public void onClick(int position, String id) {
                infoItemAdapter.setSelection(position);
                infoItemAdapter.notifyDataSetChanged();
            }
        });
    }

    private void initToolbar() {
        setSupportActionBar(toolbar);
        toolbar.setTitle("专家问答");
        toolbar.setTitleTextColor(getResources().getColor(R.color.white));
        toolbar.setNavigationIcon(R.mipmap.btn_exit);
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
                Intent intent;
                switch (item.getItemId()) {
                    case R.id.btn_my_quiz: {
                        intent = new Intent(ProfessorAnswerActivity.this, MyQuizListActivity.class);
                        startActivity(intent);
                    }
                }
                return false;
            }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_professor_answer, menu);
        return true;
    }
}
